#define _GNUC_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void *thread_func1(void *arg)
{
    int i = 0;
    while (1) {
        printf("thread1 %d*******\n",gettid());
        sleep(1);
        if (i==5)
        {
            return NULL;
        }
    }
}

void *thread_func2(void *arg)
{
    int i = 0;
    while (1) {
        printf("thread2 %d*******\n",gettid());
        sleep(1);
    }
}

int main(int argc, char *argv[])
{
    pthread_t thread1, thread2;

    pthread_create(&thread1, NULL, thread_func1, NULL);
    pthread_create(&thread2, NULL, thread_func2, NULL);
    sleep(10);
    pthread_cancel(thread2);

    pthread_join(thread1, NULL);
    pthread_join(thread2, NULL);

    return 0;
}